package com.eight.cloud.mybatisplus.datascope.expression;

import com.eight.cloud.core.global.constant.DataScopeConstants;
import com.eight.cloud.core.global.model.DataScopeModel;
import com.eight.cloud.core.global.model.BaseUser;
import com.eight.cloud.mybatisplus.datascope.SqlWhereExpression;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.StringValue;
import net.sf.jsqlparser.expression.operators.relational.EqualsTo;
import net.sf.jsqlparser.schema.Column;
import org.springframework.stereotype.Component;

/**
 * @ClassName: UserSelfExpression
 * @Author: TXC
 * @Date: 2025-06-11 15:50
 **/
@Component
public class UserSelfExpression implements SqlWhereExpression {
    @Override
    public Expression getExpression(Column column, BaseUser currentUser, DataScopeModel dataScopeModel) {
        // 构造本人eq表达式
        return new EqualsTo(column, new StringValue(currentUser.getUuid()));
    }

    @Override
    public boolean isSupport(DataScopeModel dataScopeModel) {
        return !dataScopeModel.getDataScope().equals(DataScopeConstants.DATA_SCOPE_ALL);
    }
}
